package com.ruoyi.ai.config;

import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author coach tam
 * @email 327395128@qq.com
 * @values 坚持灵活 灵活坚持
 * @since 2025/4/1
 */
@Configuration
public class OpenAIConfig {

    @Value("${spring.ai.openai.api-key}")
    private String apiKey;

    @Value("${spring.ai.openai.base-url:https://api.openai.com}")
    private String baseUrl;

    @Bean
    public OpenAiApi openAiApi() {
        return OpenAiApi.builder().apiKey(apiKey).baseUrl(baseUrl).build();
    }

    @Bean("chatModel")
    public OpenAiChatModel chatModel(OpenAiApi openAiApi) {
        OpenAiChatOptions openAiChatOptions = new OpenAiChatOptions();
        openAiChatOptions.setTemperature(0.7);
        openAiChatOptions.setMaxTokens(1000);
        openAiChatOptions.setModel("qwen-turbo");
        return OpenAiChatModel.builder().openAiApi(openAiApi).defaultOptions(openAiChatOptions).build();
    }

    @Bean("visionModel")
    public OpenAiChatModel visionModel(OpenAiApi openAiApi) {
        OpenAiChatOptions openAiChatOptions = new OpenAiChatOptions();
        openAiChatOptions.setTemperature(0.7);
        openAiChatOptions.setMaxTokens(1000);
        openAiChatOptions.setModel("qwen-vl-plus");
        return OpenAiChatModel.builder().openAiApi(openAiApi).defaultOptions(openAiChatOptions).build();
    }
}
